function xnew = combine_cells(titulo,div,varargin ); 
% ================================================================
%           COMBINE_CELLS 
% function xnew = combine_cells(titulo,div,varargin ); 
%
% Combine cells into a new cell 
% With title given by titulo and divided by div 
% Note: One of the cells may be unidimensional in which case it will 
% be replicated to the largest size available although it cannot be the
% first element 
% 
% Inputs 
% If TITULO not provided , [], do not modify output cell. 
%    Otherwise add row on top 
% 
% DIV   Divisor, if not provided is ' ' 
% 
% Use COMBINE_MATCELLS.m for more sophisticated combinations 
% AJ 9/26/2005 
% ====================================================================

nx = length( varargin ) ; 
x1 = varargin{1}; 
[nr,nc] = size( x1 ); 
clear x1; 

ind = 0; 
xnew = emptycell( nr +1 , nc  ); 
if ~isempty( titulo );
    ind = ind + 1; 
    xnew( 1, 1 ) = cellstr( titulo ); 
else 
    xnew = xnew(2:end,:); 
end 

if isempty( div ); 
    div = ''; 
end 

tcell = emptycell( nr , nc ); 

ii = 1;
for ii = 1:nx ;

    xt = varargin{ii};
    if isnumeric( xt ) == 1 ;
        xt = num2cprec( xt ) ;
    end

    temp = size( xt ); 
    if any( temp ~= [nr nc]  ) == 1 
        if min( temp ) == 1; 
            xt = fillcell( nr , nc , char(xt) ) ; 
        else 
            error('Different dimension cell combinations') 
        end 
    end 
    clear filcell 
        
    
    jj = 1 ;
    for jj =1:nr ;
        kk = 1;
        for kk = 1:nc;

            if ii > 1
                temp = cellstr( [char(tcell(jj,kk)),div, char( xt(jj,kk) )] );
                tcell( jj,kk) = temp ;
            else
                tcell( jj,kk ) = xt( jj , kk );
            end

        end
    end

    clear xt;

end
xnew(ind+1:end,:) = tcell; 



        